package com.caogen.cg_wl_kt.ui.login

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.result.contract.ActivityResultContracts
import com.caogen.cg_wl_kt.base.BaseActivity
import com.caogen.cg_wl_kt.databinding.ActivityLoginBinding
import com.caogen.cg_wl_kt.vmodel.login.LoginViewModel
import com.caogen.cg_wl_kt.utils.PrefUtils
import com.caogen.cg_wl_kt.utils.YDLog

class LoginActivity : BaseActivity<ActivityLoginBinding, LoginViewModel>(
    ActivityLoginBinding::inflate,
    LoginViewModel::class.java
){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }
    override fun setListener(){
        setOnClickListener(binding.btnLogin,binding.tvRegister,binding.tvForget)
    }
    override fun onClick(v: View?) {
        super.onClick(v)
        if(v == binding.btnLogin){
            viewModel.login(this)
        }
        if(v == binding.tvRegister){
            var intent = Intent(this,RegisterActivity::class.java);
            activityResultLauncher.launch(intent)
        }
        if(v == binding.tvForget){
            var intent = Intent(this,UpdatePwdActivity::class.java);
            activityResultLauncher.launch(intent)
        }
    }
    override fun setActivityResult(){
        activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){
            if (it.resultCode == RESULT_OK){
                val test_name = it.data?.getStringExtra(PrefUtils.RESULT_NAME)
                if (test_name.equals("yd_test1")){
                    val test = it.data?.getStringExtra("test")
                    YDLog.logd(test.toString())
                }else if (test_name.equals("yd_test2")){
                    val test = it.data?.getStringExtra("test")
                    YDLog.logd(test.toString())
                }
            }else{

            }
        }
    }
}